16. Exercise: Frames
22 17 AAK Frame Intro SC
Android Developer Documentation
Exercise
In this exercise you are going to draw a frame around the sketch.
- In
MyCanvasView, add a variable calledframethat holds aRectobject.
private lateinit var frame: Rect
- In
onSizeChanged()add code to create theRectthat will be used for the frame, using the new dimensions and the inset.
// Calculate a rectangular frame around the picture.
val inset = 40
frame = Rect(inset, inset, width - inset, height - inset)
- In
onDraw(), after drawing the bitmap, draw a rectangle.
// Draw a frame around the canvas.
canvas.drawRect(frame, paint)
- Run your app. Notice the frame.